package jicheng;

//遍历字符串（重点）

import java.util.Scanner;

public class StringTest02 {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        System.out.println("请输入一个字符串");
        String line = sc.nextLine();

        System.out.println("遍历方式1");

        for (int i = 0; i < line.length(); i++) {
            //获取字符串当中对应索引位置的字符
            char c =line.charAt(i);
            System.out.println(c);
        }

        System.out.println("遍历方式2");
        //将字符串转换为字符数组
        char[] arr = line.toCharArray();

        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i]);
        }
    }
}